<?php
	/**
	 * Database driver
	 * 
	 * @author Anton.Perkin
	 *
	 */
	class DB
	{
		static $dbConfig = array
		(
			'host' => 'localhost',
			'username' => 'root',
			'password' => 'kerdan',
			'db' => 'jb_pc',
//			'host' => 'localhost',
//			'username' => 'root',
//			'password' => 'kerdan',
//			'db' => 'winelist',
//			'host' => 'edie-instance.cw32ap7bnr05.us-east-1.rds.amazonaws.com',
//			'username' => 'root',
//			'password' => 'aPassw0rd',
//			'db' => 'vineloop',
		);
		
		/**
		 * Executes SQL
		 *
		 * @param string $sql SQL to execute
		 */
		static function ExecuteSQL($sql)
		{
			$mysqli = new mysqli(self::$dbConfig['host'], self::$dbConfig['username'], self::$dbConfig['password'], self::$dbConfig['db']);
			$mysqli->set_charset('utf8');
			$result = $mysqli->real_query($sql);	
			return $result;
		}

		/**
		 * List items
		 *
		 * @param string $sql SQL to execute
		 * 
		 * @return array
		 */
		static function ListItems($sql)
		{
			$mysqli = new mysqli(self::$dbConfig['host'], self::$dbConfig['username'], self::$dbConfig['password'], self::$dbConfig['db']);
			$mysqli->set_charset('utf8');
			
			$result = $mysqli->multi_query($sql);
			$mysqli->next_result();
			$objects = array();
			if ($result = $mysqli->store_result())
			{
			   while ($object = $result->fetch_array(MYSQLI_ASSOC))
			   {
			       $objects[] = $object;
			   }
			   $result->close();
			}
			$mysqli->close();
			
			return $objects;			
		}
		
	}

?>